package com.xing.controller;

import com.xing.DTO.RoleMenuSaveDTO;
import com.xing.Utils.Result;
import com.xing.entity.SysRoleMenuEntity;
import com.xing.service.SysRoleMenuService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "角色权限关联服务")
@RestController
@RequestMapping(value = "roleMenuRelation")
public class SysRoleMenuController {

    @Autowired
    private SysRoleMenuService roleMenuService;


    @Operation(summary = "根据角色id获取权限id")
    @GetMapping(value = "getMenuIdByRoleId")
    @PreAuthorize("hasAnyAuthority('admin')")
    public Result getMenuIdByRoleId(@RequestParam Long roleId) {
        List<Long> menuIdList = roleMenuService.getMenuIdByRoleId(roleId);
        return new Result().ok(menuIdList);
    }


    @Operation(summary = "授予角色权限列表")
    @PostMapping(value = "saveRoleMenu")
    @PreAuthorize("hasAnyAuthority('admin')")
    public Result saveRoleMenuRelation(@RequestBody RoleMenuSaveDTO roleMenuSaveDTO) {
        return roleMenuService.saveUserRoleRelation(roleMenuSaveDTO);
    }

}
